#include "statusbar.h"

StatusBar  *StatusBar::pStatusBar  = 0;
QStatusBar *StatusBar::pQStatusBar = 0;


StatusBar::StatusBar()
{
}

StatusBar::~StatusBar()
{
}

bool StatusBar::addWidget(std::string name, QWidget *widget, int stretch)
{
  bool ret_value = true;
  if(widgetFactory.getRegisterClass(name) != 0) {
    ret_value = false;
  } else {
    pQStatusBar->addWidget(widget, stretch);
    widgetFactory.Register(REGISTER_OBJECT(QWidget, widget), name);
  }
  return ret_value;
}

int  StatusBar::insertWidget(std::string name, int index, QWidget *widget, int stretch)
{
  int ret_value = -1;
  if(widgetFactory.getRegisterClass(name) == 0) {
    ret_value = pQStatusBar->insertWidget(index, widget, stretch);
    if(ret_value >= 0)
      widgetFactory.Register(REGISTER_OBJECT(QWidget, widget), name);
  }
  return ret_value;
}

bool StatusBar::addPermanentWidget(std::string name, QWidget *widget, int stretch)
{
  bool ret_value = true;
  if(widgetFactory.getRegisterClass(name) != 0) {
    ret_value = false;
  } else {
    pQStatusBar->addPermanentWidget(widget, stretch);
    widgetFactory.Register(REGISTER_OBJECT(QWidget, widget), name);
  }
  return ret_value;
}

int  StatusBar::insertPermanentWidget(std::string name, int index, QWidget *widget, int stretch)
{
  int ret_value = -1;
  if(widgetFactory.getRegisterClass(name) == 0) {
    ret_value = pQStatusBar->insertPermanentWidget(index, widget, stretch);
    if(ret_value >= 0)
      widgetFactory.Register(REGISTER_OBJECT(QWidget, widget), name);
  }
  return ret_value;
}

void StatusBar::removeWidget(std::string name)
{
  QWidget *widget = 0;
  if((widget = widgetFactory.getRegisterClass(name)) != 0) {
    pQStatusBar->removeWidget(widget);
    widgetFactory.deRegitrateObject(name);
  }
}

QWidget *StatusBar::getWidget(std::string name)
{
  return widgetFactory.getRegisterClass(name);
}
